import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_app/config/app_colors.dart';
import 'package:flutter_app/typedef/function.dart';
import 'package:flutter_app/util/auto_ui.dart';

class SongTop extends StatelessWidget {
  SongTop({Key key, this.onChanged, this.onNotice}) : super(key: key);

  ///输入框输入监听
  final ParamSingleCallback<String> onChanged;

  ///消息回调
  final ParamVoidCallback onNotice;

  @override
  Widget build(BuildContext context) {
    return _buildBg(children: [
      _logo(),
      Expanded(child: _searchContent()), //撑满屏幕，下一个图片就会到最右边
      _msg()
    ]);
  }

  ///logo
  Widget _logo() {
    return Image.asset(
      'assets/images/common/logo.png',
      height: 40,
    );
  }

  ///搜索
  Widget _searchContent() {
    return Container(
      height: 30,
      margin: EdgeInsets.symmetric(horizontal: 15.dp),
      decoration: BoxDecoration(
        color: AppColors.page,
        borderRadius: BorderRadius.circular(30),
      ),
      child: Row(
        children: [
          Padding(
            padding: EdgeInsets.only(left: 6, right: 2),
            child: Icon(
              Icons.search,
              size: 16,
              color: AppColors.un3active,
            ),
          ),
          //输入框
          Expanded(
            child: TextField(
              autofocus: false,

              ///是否自动聚焦
              textAlign: TextAlign.start,

              ///对齐方式
              textInputAction: TextInputAction.search,

              ///键盘按钮
              maxLines: 1,

              ///最多行数
              decoration: InputDecoration(
                ///较小空间时，使组件正常渲染，包括文本垂直居中
                isDense: true,
                border: InputBorder.none,

                ///边框
                contentPadding: EdgeInsets.all(0.0),

                ///内填充
                hintText: '搜索关键词',

                ///输入提示
                hintStyle:
                    TextStyle(fontSize: 12.sp, color: AppColors.un3active),
              ),
              onChanged: onChanged,
            ),
          )
        ],
      ),
    );
  }

  Widget _msg() {
    return GestureDetector(
      child: Image.asset(
        'assets/images/icons/msg.png',
        height: 30,
      ),
      onTap: onNotice,
    );
  }

  Widget _buildBg({List<Widget> children}) {
    return Row(
      mainAxisAlignment: MainAxisAlignment.spaceBetween,
      children: children,
    );
  }
}
